package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.MenuBean;
import com.hengxinguotong.zhihuichengjian.utils.Utils;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/11/1.
 */

public class HomeMenuListAdapter extends BaseAdapter {

    private List<MenuBean> menuList;

    public HomeMenuListAdapter(List<MenuBean> menuList, Context context) {
        this.menuList = menuList;
    }

    public void setMenuList(List<MenuBean> menuList) {
        this.menuList = menuList;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return menuList.size();
    }

    @Override
    public Object getItem(int position) {
        return menuList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null || convertView.getTag() == null) {
            convertView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.item_menu, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        MenuBean menuBean = menuList.get(position);
        holder.menuName.setText(menuBean.getName());
        int icon = Utils.getIconByUrl(menuBean.getId());
        if (icon > 0) {
            holder.menuIcon.setImageResource(icon);
        }
//        switch (menuBean.getId()) {
//            case 100:
//                holder.menuIcon.setImageResource(R.mipmap.icon_shipinjiankong);
//                break;
//            case 200:
//                holder.menuIcon.setImageResource(R.mipmap.icon_renyuanguanli);
//                break;
//            case 300:
//                holder.menuIcon.setImageResource(R.mipmap.icon_zhiliangguanli);
//                break;
//            case 400:
//                holder.menuIcon.setImageResource(R.mipmap.icon_anquanguanli);
//                break;
//            case 500:
//                holder.menuIcon.setImageResource(R.mipmap.icon_shebeiguanli);
//                break;
//            case 600:
//                holder.menuIcon.setImageResource(R.mipmap.icon_cailiaoguanli);
//                break;
//            case 700:
//                holder.menuIcon.setImageResource(R.mipmap.icon_huanjingjianche);
//                break;
//            case 800:
//                holder.menuIcon.setImageResource(R.mipmap.icon_gongchenguanli);
//                break;
//            case 900:
//                holder.menuIcon.setImageResource(R.mipmap.icon_wendangguanli);
//                break;
//            case 1000:
//                holder.menuIcon.setImageResource(R.mipmap.icon_nenghaojiance);
//                break;
//            case 1100:
//                holder.menuIcon.setImageResource(R.mipmap.icon_diaogouguanli);
//                break;
//            case 1300:
//                holder.menuIcon.setImageResource(R.mipmap.icon_gaozhimo);
//                break;
//            case 1400:
//                holder.menuIcon.setImageResource(R.mipmap.icon_anquanpeixun);
//                break;
//            case 280:
//                holder.menuIcon.setImageResource(R.mipmap.icon_cheliangguanli);
//                break;
//        }
        if(menuBean.isHasNew()){
            holder.messageNew.setVisibility(View.VISIBLE);
        }else{
            holder.messageNew.setVisibility(View.GONE);
        }
        return convertView;
    }

    static class ViewHolder {
        @BindView(R.id.menu_icon)
        ImageView menuIcon;
        @BindView(R.id.menu_name)
        HXTextView menuName;
        @BindView(R.id.message_new)
        ImageView messageNew;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
